import { BodySetup } from "utils/creep/CreepSetup";
import { ActionBase, ActionBaseOfCreep } from "../ActionBase";
import { priority } from "utils/constants/definetypes";
import { role_crossLevel } from "utils/constants/moveConstant";
import { EActionCode } from "framework/FSM/Action/ActionCode";

/**
 * 升级Action
 */
export class ActionRenewCreep  extends ActionBaseOfCreep<IActionCMD<"renewCreep">>
{
    protected _execute(action: IActionCMD<"renewCreep">): ActionCode 
    {
        const creep = action.arg.entity;
       
        if(creep.memory.spawn)
        {
            const spawn = Game.spawns[creep.memory.spawn];
            if(!spawn.spawning)
            {
                if(creep.pos.distance(spawn.pos)>1)
                {
                     
                    creep.mymoveTo({pos:spawn.pos,range:1},{});
                }
                else
                {
                    
                    const code = spawn.renewCreep(creep);
                    return EActionCode.OK;
                }
            }
            else
            {
                 
            }
        }
        else
        {
           
            const spawnEntity = action.arg.room.getEntity("SpawnEntity");
            spawnEntity.allocRenewSlot(creep);
        }
        return EActionCode.RUNNING;
    }
}